package com.it.controller;

import cn.dev33.satoken.util.SaResult;
import com.github.pagehelper.PageInfo;
import com.it.bean.Question;
import com.it.page.PageImpl;
import com.it.page.PageQuery;
import com.it.service.QuestionService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/question")
public class QuestionController {
    private final QuestionService questionService;

    @PostMapping("/page")
    public SaResult page(@RequestBody PageQuery<Question> pageQuery) {
        PageInfo<Question> pageInfo = questionService.page(pageQuery);
        return SaResult.data(PageImpl.of(pageInfo));
    }

    @PostMapping("/delete/{id}")
    public SaResult del(@PathVariable("id") Long id) {
        questionService.delete(id);
        return SaResult.ok();
    }

    @PostMapping("/save")
    public SaResult save(@RequestBody Question question) {
        questionService.save(question);
        return SaResult.ok();
    }
}
